﻿using BSChuangXu.API.Read.Appicant.Commend.RoleCommend;
using BSChuangXu.Domain.User;
using BSChuangXu.ErrorCode;
using BSChuangXu.Infrastructure.Interface;
using MediatR;
using System.Data;

namespace BSChuangXu.API.Read.Appicant.CommendHandel.RoleCommandHandler
{
    /// <summary>
    /// 角色反填
    /// </summary>
    public class RoleFanTianCommandHandler : IRequestHandler<RoleFanTianCommand, APIResult<RoleModel>>
    {
        public readonly IBaseRepository<RoleModel> roleRepos;
        public RoleFanTianCommandHandler(IBaseRepository<RoleModel> roleRepos)
        {
            this.roleRepos = roleRepos;
        }
        /// <summary>
        /// 角色反填
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<APIResult<RoleModel>> Handle(RoleFanTianCommand request, CancellationToken cancellationToken)
        {
            APIResult<RoleModel> result = new APIResult<RoleModel>();
            var obj = roleRepos.GetAll().Result.FirstOrDefault(x => x.RoleId == request.RoleId);
            if (obj == null)
            {
                result.Code = APIEnum.查询失败;
                result.Msg = APIEnum.查询失败.ToString();
            }
            else
            {
                result.Code = APIEnum.查询成功;
                result.Msg = APIEnum.查询成功.ToString();
                result.data = obj;
            }
            return Task.FromResult(result);
        }
    }
}
